package com.sumainfor.pc.epc.controller.MarketFeign;

import com.netflix.discovery.converters.Auto;
import com.sumainfor.common.config.RedisUtils;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.epc.service.impl.FeignMkt.HousingPlanServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 房源配置
 * @Auther: zhlu
 * @Date: 2018/12/19 17:10
 * @Description:
 */
@RestController
@RequestMapping("/key/hou")
public class HousingPlanController {

    @Autowired
    HousingPlanServiceImpl housingPlan;

    @Autowired
    RedisUtils RedisUtils;

    @ResponseBody
    @RequestMapping(value = "/AddHousingPlan",method = RequestMethod.POST)
    public JsonResult AddHousingPlan(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(housingPlan.AddHousingPlan(params)){
            result.putSuccess("房源配置成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 功能描述:
     * 根据房源编号获取房源套餐
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/22 12:28
     */
    @GetMapping("/getHousingPlanList")
    public JsonResult getHousingPlanList(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouId"})){
            result.putFailed("工程部HouId不能为空！");
        }else{
            result.put(housingPlan.getHousingPlanList(params));
        }
        return result;
    }

    /**
     * 功能描述:
     * 获取配置变更的房源存入Redis
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/12/24 15:29
     */
    @GetMapping("/getHousingPlanAmendList")
    public JsonResult getHousingPlanAmendList(){
        JsonResult result=new JsonResult();
        List<Map<String,Object>>getHousingPlanAmendList=housingPlan.getHousingPlanAmendList(new HashMap<String,Object>(){{
            put("IfAmend",1);//是否被修改  0未修改  1修改
            put("IfRead",0);//是否已读  0未读   1已读
            put("delfg",0);
        }});
        result.put(getHousingPlanAmendList);
        return result;
    }
}
